<?php $CI =& get_instance();?>
<script>
APP = $merge(APP, {
	base: '<?php echo site_url(array('users',$usrAlias,'perbuatan'))?>',
	utils: '<?php echo site_url(array('utils'))?>',
	saksiCount:1
});
</script>
<h2 style="border-bottom: 1px solid #ccc;">
	Preview Perbuatan :: <?php echo $perbData['perb_id']?>
</h2>
<div id="detailView">
<h3 style="padding-bottom: 5; margin-bottom: 0; display: inline;">- Laporan Perbuatan</h3>
<h4 style="padding-bottom: 5; margin-bottom: 0; padding-left: 10px ">Pelapor</h4>
<table cellpadding="5" style="margin-left: 5px" cellspacing="0" width="100%">
<?php if ($laporData['lapor_nik']):?>
<tr>
	<td>NIK:</td>
	<td colspan="2"><?php echo $laporData['lapor_nik']?></td>
</tr>
<?php endif;?>
<tr>
	<td width="20%">Nama:</td>
	<td colspan="2"><?php echo $laporData['lapor_nama']?></td>
</tr>
<tbody id="noPelaporID" style="display: table-row-group; ">
<?php if ($laporData['lapor_nik']): ?>
<?php $CI->load->model('pelapor_alamat_model')?>
<?php $alamat = $CI->pelapor_alamat_model->select_by_pelapor($laporData['lapor_id'])?>
<?php foreach ($alamat->result_array() as $row):?>
<tr>
	<td>Alamat:</td>
	<td width="40%"><?php echo $row['lapor_alm_alamat']?></td>
	<td valign="top"><?php echo $row['lapor_alm_kota']?></td>
</tr>
<?php endforeach;?>
<?php $CI->load->model('pelapor_telepon_model')?>
<?php $tlp = $CI->pelapor_telepon_model->select_by_pelapor($laporData['lapor_id'])?>
<?php foreach($tlp->result_array() as $row):?>
<tr>
	<td>Telepon:</td>
	<td><?php echo $row['lapor_tlp_no']?>
	</td>
</tr>
<?php endforeach;?>
<?php endif;?>
</tbody>
</table>

<h4 style="padding-bottom: 5; margin-bottom: 0; padding-left: 10px ">Perbuatan</h4>
<table cellpadding="5" style="margin-left: 5px" cellspacing="0" width="100%">
<tr>
	<td width="20%">Tanggal Lapor:</td>
	<td><?php echo $perbData['perb_tgl_lapor']?></td>
</tr>
<tr>
	<td>Tanggal Kejadian:</td>
	<td><?php echo $perbData['perb_tgl_kejadian']?></td>
</tr>
<tr>
	<td>Tempat Kejadian:</td>
	<td><?php echo $perbData['perb_tempat_kejadian']?></td>
</tr>
<tr>
	<td valign="top"><div style="padding-top: 2px">Kategori Perbuatan:</div></td>
	<td><?php echo $deperbData[0]['detachiev_nama']?>
	</td>
</tr>
<tr>
	<td width="50px">Jenis:</td>
	<td><?php echo $jenis_options[$deperbData[0]['achiev_jenis']]?></td>
</tr>
<tr>
	<td>Bidang:</td>
	<td><?php echo $deperbData[0]['achiev_bidang']?></td>
</tr>
<tr>
	<td>Tingkat:</td>
	<td><?php echo $tingkat_options[$deperbData[0]['detachiev_tingkat']]?></td>
</tr>
<tr>
	<td>Karyawan Pelaku:</td>
	<td>
		<?php $TMP = (array)$CI->karyawan_model->select_by_id($deperbData[0]['kary_id'])->row()?>
		<?php echo $TMP['kary_nama']?>
		<?php foreach ($CI->karyawan_history_jabatan_model->select_by_id($deperbData[0]['kary_jbt_id'])->result_array() as $row):?>
			<?php if ($row['kary_jbt_id']==$deperbData[0]['kary_jbt_id']) echo $row['jbt_nama']." [".$row['dep_nama']."]"?>
		<?php endforeach;?>
	</td>
</tr>
<?php
$ind=1;
foreach($deperbData as $pelaku):
if ($pelaku['kary_id'] == $deperbData[0]['kary_id']) continue; //skip the first index 
?>
<tr>
	<td></td>
	<td>
		<?php $TMP = (array)$this->karyawan_model->select_by_id($pelaku['kary_id'])->row()?>
		<?php echo $TMP['kary_nama']?>
		<?php foreach ($CI->karyawan_history_jabatan_model->getActive($pelaku['kary_id'])->result_array() as $row):?>
			<?php if ($pelaku['kary_jbt_id']==$row['kary_jbt_id']) echo $row['jbt_nama']." [".$row['dep_nama']."]"?>
		<?php endforeach;?>
	</td>
</tr>
<?php endforeach?>
<tr>
	<td valign="top"><div style="padding-top: 2px" >Keterangan:</div></td>
	<td><?php echo trim($perbData['perb_keterangan'])?></td>
</tr>
<tr>
	<td valign="top"><div style="padding-top: 2px">Bukti:</div></td>
	<td>
		<div id="fcUpload"> 
		<ul id="fcUpload-list">
			<?php foreach($buktiperbData as $bukti):?>
			<li class="file " id="file-1" style="background-color: transparent; ">
				<a class="file-title fakeLink" onclick="showImage(
					'<?php echo $bukti['perb_dok_file_name'] ?>',
					'<?php echo $bukti['perb_dok_file_name']?>',
					APP.base+'/ajax/loadImage/<?php echo $bukti['perb_dok_id']?>')">
					<?php echo $bukti['perb_dok_file_name']?>
				</a>
				<span class="file-size"><?php echo number_format($bukti['perb_dok_file_size']/1024,2)." kB"?></span>
			</li>
			<?php endforeach?>
		</ul> 
	</div> 
 	</td>
</tr>
</table>
<div style="border-top:1px solid #ccc; text-align: center; padding-top: 10px; margin-top: 20px">
	<input type="button" value="Approve" class="buttonRed" onclick="doApprove()" />
	<input type="button" value="Reject" class="buttonRed" onclick="doReject()" />
	<input type="button" value="Cancel" class="button" onclick="document.location=APP.base" />
</div>
</div>


<div id="approveView">
<form action="<?php echo site_url(array('users',$usrAlias,'perbuatan','ajax','persetujuan','approve'))?>" method="post">
<h3 style="padding-bottom: 5; margin-bottom: 0; padding-top: 5px; margin-top: 0">- Approve Notification</h3>
<div id="msg[RA]" style="width: 600px"></div>

<?php 
	$CI->load->model('perbuatan_notifikasi_model');
	$CI->load->model('perbuatan_detil_model');
    $CI->load->model('karyawan_history_jabatan_model');
    $CI->load->model('jabatan_model');
	$CI->load->model('karyawan_model');
	$CI->load->model('nilai_model');
	
	//kita cari karyaawan yang memberikan approve berjabatan apa dari karyawan yang melakukan tindakan
	$jabatanThisKaryawan = '';
	foreach($deperbData as $row){
		//jabatan 
    	$kary_jbt_id = $row['kary_jbt_id'];
    	$jbt_id = $CI->karyawan_history_jabatan_model->select_by_id($kary_jbt_id)->row();
    	$jbt_id = $jbt_id->jbt_id;		//jabatan pelaku
    	
    	//kita cari supervisor jabatan tersebut, dan siapa karyawan yg menjabat
    	$jbt_supervisi = $CI->jabatan_model->getSupervisor($jbt_id);	//jabatannya
    	$usr_supervisi = $CI->karyawan_history_jabatan_model->getKaryawanActive($jbt_supervisi);	//karyawannya dari jabatan tersebut
    	if ($usr_supervisi == $usrName) {
    		$jabatanThisKaryawan = 	$jbt_supervisi;
    		break;	//kita asumsikan ini jabatannya
    	} 
	}
	
	$saksiSearchExclude ="";
	$saksiSearchExclude = ($saksiSearchExclude? ",":"")."'".$usrName."'";	//exclude user
	$karyData = (array)$CI->karyawan_model->select_by_id($usrName)->row();
    $jbtData = (array)$CI->jabatan_model->select_by_id($jabatanThisKaryawan)->row();
    $karyJbtData = (array)$CI->karyawan_history_jabatan_model->getActiveJbt($karyData['kary_id'], $jbtData['jbt_id'])->row();
    $inp['pembuat'] = array('kary_id'=>$karyData['kary_id'],'jbt_id'=>$karyJbtData['kary_jbt_id']);
?>

<textarea name="inp[AP][keterangan]" class="RTE validate['required','target:msg[RA]']">
<?php if ($deperbData[0]['achiev_jenis']=='PE'):?>
	<p>Pemeriksa<br />
	Nama: <strong><?php echo $karyData['kary_nama']?></strong><br/>
	NIK : <strong><?php echo $karyData['kary_id']?></strong><br/>
	Jabatan : <strong><?php echo $jbtData['jbt_nama']?> [<?php echo $jbtData['dep_nama']?>]</strong></p>
	<p>Berdasarkan laporan <strong>PERB/NO.<?php echo $perbData['perb_id']?></strong> tertanggal 
		<strong><?php echo date("d-F-Y",strtotime($perbData['perb_tgl_lapor']))?></strong> 
		pukul <strong><?php echo date("H:i",strtotime($perbData['perb_tgl_lapor']))?></strong> WIB, para pelaku:</p>
<?php 
	//kita bagi menurut atasan masing2
	foreach($deperbData as $row):
		$saksiSearchExclude .= ($saksiSearchExclude? ",":"")."'".$row['kary_id']."'";		//exclude pelaku
    	//jabatan 
    	$kary_jbt_id = $row['kary_jbt_id'];
    	$jbt_id = $CI->karyawan_history_jabatan_model->select_by_id($kary_jbt_id)->row();
    	$jbt_id = $jbt_id->jbt_id;		//jabatan pelaku
    	
    	//kita cari supervisor jabatan tersebut, dan siapa karyawan yg menjabat
    	$jbt_supervisi = $CI->jabatan_model->getSupervisor($jbt_id);	//jabatannya
    	$usr_supervisi = $CI->karyawan_history_jabatan_model->getKaryawanActive($jbt_supervisi);	//karyawannya dari jabatan tersebut
    	if ($usr_supervisi != $usrName) continue;
    	
    	$karyData = (array)$CI->karyawan_model->select_by_id($row['kary_id'])->row();
    	$jbtData = (array)$CI->jabatan_model->select_by_id($jbt_id)->row();
?>
	<p>Nama : <strong><?php echo $karyData['kary_nama']?></strong><br/>
	NIK : <strong><?php echo $karyData['kary_id']?></strong><br/>
	Jabatan : <strong><?php echo $jbtData['jbt_nama']?> [<?php echo $jbtData['dep_nama']?>]</strong><br />
	<?php 
		//kita cari hukumannya
		$hukumanCount = $CI->perbuatan_detil_model->count($karyData['kary_id'], $jbt_id, $row['detachiev_id'], $perbData['perb_tgl_lapor']);
		$hukumanData = (array)$CI->nilai_model->getPunishment($row['detachiev_id'], $hukumanCount+1);
	?>
	pihak tersebut mendapatkan 
		<?php if ($row['achiev_jenis']=='PR'):?>reward 
		<?php elseif($row['achiev_jenis']=='RE'):?>punishment
		<?php endif?>
	 <strong><?php echo $hukumanData['reward_nama']?></strong></p>
<?php endforeach?>
<?php endif?>
</textarea>

<h3 style="padding-bottom: 5; margin-bottom: 0; padding-left: 10px ">Saksi</h3>
<table style="width: 100%" cellpadding="5">
<?php if ($laporData['lapor_nik'] != ""):?>
<?php $saksiSearchExclude.= ($saksiSearchExclude? ",":"")."'".$laporData['lapor_nik']."'";	//exclude saksi ?>
<tr>
	<td>Pelapor : </td>
	<td>
		<input type="text" value="<?php echo $laporData['lapor_nama']?>" disabled="disabled" />
		<input id="tpl_saksi2" type="hidden" name="inp[AP][pelapor]" value="<?php echo $laporData['lapor_nik']?>" />
		<input type="hidden" value="asdsad" style="margin-left: 5px" />
	</td>
</tr>
<?php endif?>
<tr>
	<td>Saksi: </td>
	<td>
		<input id="tpl_saksi1" type="text" name="inp[AP][saksi][1][1]" value="" disabled="disabled" />
		<input id="tpl_saksi2" type="hidden" name="inp[AP][saksi][1][0]" value="" />
		<input id="tpl_saksi3" type="button" value="Search" style="margin-left: 5px" class="button" />
	</td>
</tr>
<tr>
	<td></td>
	<td><a class="fakeLink" onclick="moreSaksi($(this))">tambah</a></td>
</tr>
</table>
<input type="hidden" name="inp[AP][perb_id]" value="<?php echo $perbData['perb_id']?>" />
<input type="hidden" name="inp[AP][pembuat][kary_id]" value="<?php echo $inp['pembuat']['kary_id']?>" />
<input type="hidden" name="inp[AP][pembuat][jbt_id]" value="<?php echo $inp['pembuat']['jbt_id']?>" />
<script>APP.saksiSearchWhere = "<?php echo $saksiSearchExclude?>";</script>
<div style="border-top:1px solid #ccc; text-align: center; padding-top: 20px; margin-top: 20px">
	<input type="submit" value="Save" class="button" />
	<input type="button" value="Cancel" class="button" onclick="doNone()" />
</div>
</form>
<table>
</table>
</div>

<div id="rejectView">
<h3 style="padding-bottom: 5; margin-bottom: 0; padding-top: 5px; margin-top: 0">- Reject Notification</h3>
<form action="<?php echo site_url(array('users',$usrAlias,'perbuatan','ajax','persetujuan','reject'))?>" method="post">
<input type="hidden" name="inp[RE][perb_id]" value="<?php echo $perbData['perb_id']?>" />
<input type="hidden" name="inp[RE][pembuat][kary_id]" value="<?php echo $inp['pembuat']['kary_id']?>" />
<input type="hidden" name="inp[RE][pembuat][jbt_id]" value="<?php echo $inp['pembuat']['jbt_id']?>" />

<div id="msg[RE]" style="width: 600px"></div>
<textarea name="inp[RE][keterangan]" cols="70" rows="5" class="RTE validate['required','target:msg[RE]']"></textarea>
<div style="border-top:1px solid #ccc; text-align: center; padding-top: 20px; margin-top: 20px">
	<input type="submit" value="Save" class="button" />
	<input type="button" value="Cancel" class="button" onclick="doNone()" />
</div>
</form>
</div>
